package com.uyaer.engine.utils
{
	import flash.geom.Point;
	import com.uyaer.engine.Globle;

	/**
	 *3d的点 
	 * @author hc
	 * 
	 */	
	public class Point3D
	{
		public var x:Number;
		public var y:Number;
		public var z:Number;
		public function Point3D(x:Number , y:Number , z:Number)
		{
			this.x = x;
			this.y = y;
			this.z = z;
		}
		
		/**
		 *两点间的距离 
		 * @param p1
		 * @param p2
		 * @return 
		 * 
		 */		
		public static function distance(p1:Point3D , p2:Point3D):Number{
			var offX:Number = p1.x - p2.x;
			var offY:Number = p1.y - p2.y;
			var offZ:Number = p1.z - p2.z;
			return Math.sqrt(offX * offX + offY * offY + offZ * offZ);
		}
		
		/**
		 *2d转伪3d 
		 * @param p
		 * @return 
		 * 
		 */		
		public static function point2Dto3D(p:Point):Point3D{
			
			var d3y:Number = p.y / Globle.tanA;
			var d3x:Number = p.x;
			return new Point3D(d3x , d3y , 0);
		}
		
		public function point3Dto2D():Point{
			return new Point(x , y * Globle.tanA);
		}
		
		public static function p2dTo3dY(y:Number):Number{
			return y / Globle.tanA;
		}
		
		public static function p3dTo2dY(y:Number):Number{
			return  y * Globle.tanA;
		}
		
		/**
		 *p是否在以当前点为圆心，d为半径的圆之中
		 * @param p
		 * @param d
		 * @return 
		 * 
		 */		
		public function intersect(p:Point3D , d:Number):Boolean{
			return distance(this,p) < d ? true : false; 
		}
	}
}